<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    <title>mongodb副本集搭建 | Cucy的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="mongodb">
    <meta name="description" content="[TOC]
mongodb副本集搭建软件版本os:# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 3.4.xcat /etc/yum.repos.d/mongodb.repo[mongodb-org]name=MongoDB Repositorybaseurl=https://mirrors.tuna.tsinghua.">
<meta property="og:type" content="article">
<meta property="og:title" content="mongodb副本集搭建">
<meta property="og:url" content="http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/index.html">
<meta property="og:site_name" content="Cucy的博客">
<meta property="og:description" content="[TOC]
mongodb副本集搭建软件版本os:# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 3.4.xcat /etc/yum.repos.d/mongodb.repo[mongodb-org]name=MongoDB Repositorybaseurl=https://mirrors.tuna.tsinghua.">
<meta property="og:updated_time" content="2019-02-22T05:28:07.836Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="mongodb副本集搭建">
<meta name="twitter:description" content="[TOC]
mongodb副本集搭建软件版本os:# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 3.4.xcat /etc/yum.repos.d/mongodb.repo[mongodb-org]name=MongoDB Repositorybaseurl=https://mirrors.tuna.tsinghua.">
    
        <link rel="alternate" type="application/atom+xml" title="Cucy的博客" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.6.13">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.png">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">cucy</h5>
          <a href="mailto:292016176@qq.com" title="292016176@qq.com" class="mail">292016176@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/cucy" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">mongodb副本集搭建</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">mongodb副本集搭建</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-10-19T05:58:45.000Z" itemprop="datePublished" class="page-time">
  2017-10-19
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#mongodb副本集搭建"><span class="post-toc-number">1.</span> <span class="post-toc-text">mongodb副本集搭建</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#软件版本"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">软件版本</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#安装"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">安装</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#创建keyfile"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">创建keyfile</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#配置文件-配置详情"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">配置文件 配置详情</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#启动"><span class="post-toc-number">1.5.</span> <span class="post-toc-text">启动</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#初始化副本集"><span class="post-toc-number">1.6.</span> <span class="post-toc-text">初始化副本集</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#创建用户"><span class="post-toc-number">1.7.</span> <span class="post-toc-text">创建用户</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#测试复制集可用"><span class="post-toc-number">1.8.</span> <span class="post-toc-text">测试复制集可用</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#rs-status"><span class="post-toc-number">1.9.</span> <span class="post-toc-text">rs.status()</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#rs-printReplicationInfo-类似binlong"><span class="post-toc-number">1.10.</span> <span class="post-toc-text">rs.printReplicationInfo() 类似binlong</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#db-serverStatus-当前实例详细信息"><span class="post-toc-number">1.11.</span> <span class="post-toc-text">db.serverStatus() 当前实例详细信息</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#db-serverBuildInfo-mongodb编译环境信息"><span class="post-toc-number">1.12.</span> <span class="post-toc-text">db.serverBuildInfo() mongodb编译环境信息</span></a></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#mongos路由"><span class="post-toc-number">2.</span> <span class="post-toc-text">mongos路由</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#优化选项"><span class="post-toc-number">3.</span> <span class="post-toc-text">优化选项</span></a></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#要点"><span class="post-toc-number">4.</span> <span class="post-toc-text">要点</span></a></li></ol>
        </nav>
    </aside>
    
<article id="post-51-mongodb副本集搭建"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">mongodb副本集搭建</h1>
        <div class="post-meta">
            <time class="post-time" title="2017-10-19 13:58:45" datetime="2017-10-19T05:58:45.000Z"  itemprop="datePublished">2017-10-19</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>[TOC]</p>
<h1 id="mongodb副本集搭建"><a href="#mongodb副本集搭建" class="headerlink" title="mongodb副本集搭建"></a>mongodb副本集搭建</h1><h2 id="软件版本"><a href="#软件版本" class="headerlink" title="软件版本"></a>软件版本</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">os:</span><br><span class="line"># cat /etc/redhat-release </span><br><span class="line">CentOS Linux release 7.4.1708 (Core) </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">3.4.x</span><br><span class="line">cat /etc/yum.repos.d/mongodb.repo</span><br><span class="line">[mongodb-org]</span><br><span class="line">name=MongoDB Repository</span><br><span class="line">baseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-3.4/</span><br><span class="line">gpgcheck=0</span><br><span class="line">enabled=1</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">cat /etc/hosts</span><br><span class="line">10.76.249.128 n1</span><br><span class="line">10.76.249.129 n2</span><br><span class="line">10.76.249.130 n3</span><br></pre></td></tr></table></figure>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">yum install mongodb-org</span><br></pre></td></tr></table></figure>
<h2 id="创建keyfile"><a href="#创建keyfile" class="headerlink" title="创建keyfile"></a>创建keyfile</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">openssl rand -base64 756 &gt; /var/lib/mongo/mongokeyfile</span><br><span class="line"></span><br><span class="line">scp -p /var/lib/mongo/mongokeyfile n2:/var/lib/mongo/mongokeyfile</span><br><span class="line"></span><br><span class="line">chmod 400 /var/lib/mongo/mongokeyfile </span><br><span class="line">chown mongod:mongod /var/lib/mongo/mongokeyfile </span><br><span class="line">复制集各节点keyfile必须一致，否则复制集群初始化失败</span><br></pre></td></tr></table></figure>
<h2 id="配置文件-配置详情"><a href="#配置文件-配置详情" class="headerlink" title="配置文件 配置详情"></a>配置文件 <a href="https://docs.mongodb.com/manual/reference/configuration-options/index.html" target="_blank" rel="external">配置详情</a></h2><p><code>cat /etc/mongod.conf</code><br><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="comment"># mongod.conf</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># for documentation of all options, see:</span></span><br><span class="line"><span class="comment">#   http://docs.mongodb.org/manual/reference/configuration-options/</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># where to write logging data.</span></span><br><span class="line"><span class="attr">systemLog:</span></span><br><span class="line"><span class="attr">  destination:</span> <span class="string">file</span></span><br><span class="line"><span class="attr">  logAppend:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  path:</span> <span class="string">/var/log/mongodb/mongod.log</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Where and how to store data.</span></span><br><span class="line"><span class="attr">storage:</span></span><br><span class="line"><span class="attr">  dbPath:</span> <span class="string">/var/lib/mongo</span></span><br><span class="line"><span class="attr">  journal:</span></span><br><span class="line"><span class="attr">    enabled:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  directoryPerDB:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  engine:</span> <span class="string">wiredTiger</span></span><br><span class="line"><span class="attr">  wiredTiger:</span></span><br><span class="line"><span class="attr">    engineConfig:</span></span><br><span class="line"><span class="attr">      cacheSizeGB:</span> <span class="number">2</span></span><br><span class="line">      <span class="comment">#cacheSizeGB:1 # 默认大小 = 50%总内存 - 1GB  或者是 256MB(内存过小情况下)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># how the process runs</span></span><br><span class="line"><span class="attr">processManagement:</span></span><br><span class="line"><span class="attr">  fork:</span> <span class="literal">true</span>  <span class="comment"># fork and run in background</span></span><br><span class="line"><span class="attr">  pidFilePath:</span> <span class="string">/var/run/mongodb/mongod.pid</span>  <span class="comment"># location of pidfile</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># network interfaces</span></span><br><span class="line"><span class="attr">net:</span></span><br><span class="line"><span class="attr">  port:</span> <span class="number">27017</span></span><br><span class="line">  <span class="comment">#bindIp: [127.0.0.1,10.76.249.129]  # Listen to local interface only, comment to listen on all interfaces.</span></span><br><span class="line"><span class="attr">  bindIp:</span> <span class="string">[127.0.0.1]</span>  <span class="comment"># Listen to local interface only, comment to listen on all interfaces.</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#security:</span></span><br><span class="line"><span class="attr">security:</span></span><br><span class="line"><span class="attr">  keyFile:</span> <span class="string">/var/lib/mongo/mongokeyfile</span></span><br><span class="line"><span class="attr">  clusterAuthMode:</span> <span class="string">keyFile</span></span><br><span class="line"><span class="attr">  authorization:</span> <span class="string">enabled</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="attr">setParameter:</span></span><br><span class="line"><span class="attr">  enableLocalhostAuthBypass:</span> <span class="literal">true</span> <span class="comment"># 开启权限认证,防止数据库中没有用户,创建第一个用户必须有创建用户和授权的权限</span></span><br><span class="line">  </span><br><span class="line"><span class="comment">#operationProfiling:</span></span><br><span class="line"><span class="attr">operationProfiling:</span></span><br><span class="line"><span class="attr">   slowOpThresholdMs:</span> <span class="number">1</span> <span class="comment"># 默认100毫秒</span></span><br><span class="line"><span class="attr">   mode:</span> <span class="string">slowOp</span> <span class="comment"># 只包含oplog的慢查日志</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#replication:</span></span><br><span class="line"><span class="attr">replication:</span></span><br><span class="line"><span class="attr">  oplogSizeMB:</span> <span class="number">1024</span></span><br><span class="line"><span class="attr">  replSetName:</span> <span class="string">sanhao</span></span><br><span class="line">  <span class="comment">#secondaryIndexPrefetch: &lt;string&gt; # mmapv1有效 </span></span><br><span class="line">  <span class="comment">#enableMajorityReadConcern: &lt;boolean&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#sharding:</span></span><br><span class="line"></span><br><span class="line"><span class="comment">## Enterprise-Only Options</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#snmp:</span></span><br></pre></td></tr></table></figure></p>
<h2 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">systemctl start mongod.service</span><br></pre></td></tr></table></figure>
<h2 id="初始化副本集"><a href="#初始化副本集" class="headerlink" title="初始化副本集"></a>初始化副本集</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">rs.initiate(</span><br><span class="line">  &#123;</span><br><span class="line">    _id : &quot;sanhao&quot;,</span><br><span class="line">    members: [</span><br><span class="line">      &#123; _id : 0, host : &quot;192.168.1.52:27017&quot; &#125;,</span><br><span class="line">      &#123; _id : 1, host : &quot;192.168.1.52:27018&quot; &#125;,</span><br><span class="line">      &#123; _id : 2, host : &quot;192.168.1.52:27019&quot; &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<h2 id="创建用户"><a href="#创建用户" class="headerlink" title="创建用户"></a>创建用户</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">admin = db.getSiblingDB(&quot;admin&quot;)</span><br><span class="line">admin.createUser(</span><br><span class="line">  &#123;</span><br><span class="line">    user: &quot;root&quot;,</span><br><span class="line">    pwd: &quot;abcd123&quot;,</span><br><span class="line">    roles: [ &#123; role: &quot;root&quot;, db: &quot;admin&quot; &#125; ]</span><br><span class="line">  &#125;</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"># 集群状态</span><br><span class="line">use admin</span><br><span class="line">db.auth(&apos;root&apos;, &apos;abcd123&apos;)</span><br><span class="line">rs.status()</span><br></pre></td></tr></table></figure>
<h2 id="测试复制集可用"><a href="#测试复制集可用" class="headerlink" title="测试复制集可用"></a>测试复制集可用</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">sanhao:PRIMARY&gt; use zrd</span><br><span class="line">switched to db zrd</span><br><span class="line">sanhao:PRIMARY&gt; db.test.insert(&#123;&apos;zrdtttttt&apos;:true&#125;)</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br><span class="line"></span><br><span class="line"># 从节点验证</span><br><span class="line">mongo 10.76.249.129:27017</span><br><span class="line"></span><br><span class="line">sanhao:SECONDARY&gt; use admin</span><br><span class="line">switched to db admin</span><br><span class="line"></span><br><span class="line">sanhao:SECONDARY&gt; db.auth(&apos;root&apos;, &apos;abcd123&apos;)</span><br><span class="line">sanhao:SECONDARY&gt; rs.slaveOk()</span><br><span class="line">sanhao:SECONDARY&gt; show dbs</span><br><span class="line">admin  0.000GB</span><br><span class="line">local  0.000GB</span><br><span class="line">zrd    0.000GB</span><br><span class="line"></span><br><span class="line">sanhao:SECONDARY&gt; use zrd</span><br><span class="line">switched to db zrd</span><br><span class="line"></span><br><span class="line">sanhao:SECONDARY&gt; show tables;</span><br><span class="line">test</span><br><span class="line">sanhao:SECONDARY&gt; db.test.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;59e70ad42e1529b30c5d9def&quot;), &quot;zrdtttttt&quot; : true &#125;</span><br></pre></td></tr></table></figure>
<p>#状态查看</p>
<h2 id="rs-status"><a href="#rs-status" class="headerlink" title="rs.status()"></a>rs.status()</h2><p><a href="https://docs.mongodb.com/manual/reference/replica-states/" target="_blank" rel="external">replica state复制集状态查看</a><br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">sanhao:SECONDARY&gt; rs.status()</span><br><span class="line">&#123;</span><br><span class="line">	&quot;set&quot; : &quot;sanhao&quot;,</span><br><span class="line">	&quot;date&quot; : ISODate(&quot;2017-10-18T08:26:02.906Z&quot;),</span><br><span class="line">	&quot;myState&quot; : 2,</span><br><span class="line">	&quot;term&quot; : NumberLong(1),</span><br><span class="line">	&quot;syncingTo&quot; : &quot;192.168.1.52:27017&quot;,</span><br><span class="line">	&quot;heartbeatIntervalMillis&quot; : NumberLong(2000), # 心跳检查间隔2秒</span><br><span class="line">	&quot;optimes&quot; : &#123;</span><br><span class="line">		&quot;lastCommittedOpTime&quot; : &#123;</span><br><span class="line">			&quot;ts&quot; : Timestamp(1508315157, 1),</span><br><span class="line">			&quot;t&quot; : NumberLong(1)</span><br><span class="line">		&#125;,</span><br><span class="line">		&quot;appliedOpTime&quot; : &#123;</span><br><span class="line">			&quot;ts&quot; : Timestamp(1508315157, 1),</span><br><span class="line">			&quot;t&quot; : NumberLong(1)</span><br><span class="line">		&#125;,</span><br><span class="line">		&quot;durableOpTime&quot; : &#123;</span><br><span class="line">			&quot;ts&quot; : Timestamp(1508315157, 1),</span><br><span class="line">			&quot;t&quot; : NumberLong(1)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;,</span><br><span class="line">	&quot;members&quot; : [</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;_id&quot; : 0,</span><br><span class="line">			&quot;name&quot; : &quot;192.168.1.52:27017&quot;,</span><br><span class="line">			&quot;health&quot; : 1,</span><br><span class="line">			&quot;state&quot; : 1,</span><br><span class="line">			&quot;stateStr&quot; : &quot;PRIMARY&quot;,</span><br><span class="line">			&quot;uptime&quot; : 1676,</span><br><span class="line">			&quot;optime&quot; : &#123;</span><br><span class="line">				&quot;ts&quot; : Timestamp(1508315157, 1),</span><br><span class="line">				&quot;t&quot; : NumberLong(1)</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;optimeDurable&quot; : &#123;</span><br><span class="line">				&quot;ts&quot; : Timestamp(1508315157, 1),</span><br><span class="line">				&quot;t&quot; : NumberLong(1)</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;optimeDate&quot; : ISODate(&quot;2017-10-18T08:25:57Z&quot;),</span><br><span class="line">			&quot;optimeDurableDate&quot; : ISODate(&quot;2017-10-18T08:25:57Z&quot;),</span><br><span class="line">			&quot;lastHeartbeat&quot; : ISODate(&quot;2017-10-18T08:26:01.366Z&quot;),</span><br><span class="line">			&quot;lastHeartbeatRecv&quot; : ISODate(&quot;2017-10-18T08:26:02.647Z&quot;),</span><br><span class="line">			&quot;pingMs&quot; : NumberLong(0),</span><br><span class="line">			&quot;electionTime&quot; : Timestamp(1508313496, 1),</span><br><span class="line">			&quot;electionDate&quot; : ISODate(&quot;2017-10-18T07:58:16Z&quot;),</span><br><span class="line">			&quot;configVersion&quot; : 1</span><br><span class="line">		&#125;,</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;_id&quot; : 1,</span><br><span class="line">			&quot;name&quot; : &quot;192.168.1.52:27018&quot;,</span><br><span class="line">			&quot;health&quot; : 1,</span><br><span class="line">			&quot;state&quot; : 2,</span><br><span class="line">			&quot;stateStr&quot; : &quot;SECONDARY&quot;,</span><br><span class="line">			&quot;uptime&quot; : 1772,</span><br><span class="line">			&quot;optime&quot; : &#123;</span><br><span class="line">				&quot;ts&quot; : Timestamp(1508315157, 1),</span><br><span class="line">				&quot;t&quot; : NumberLong(1)</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;optimeDate&quot; : ISODate(&quot;2017-10-18T08:25:57Z&quot;),</span><br><span class="line">			&quot;syncingTo&quot; : &quot;192.168.1.52:27017&quot;,</span><br><span class="line">			&quot;configVersion&quot; : 1,</span><br><span class="line">			&quot;self&quot; : true</span><br><span class="line">		&#125;</span><br><span class="line">	</span><br><span class="line">	],</span><br><span class="line">	&quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">db.isMaster()</span><br></pre></td></tr></table></figure>
<h2 id="rs-printReplicationInfo-类似binlong"><a href="#rs-printReplicationInfo-类似binlong" class="headerlink" title="rs.printReplicationInfo() 类似binlong"></a>rs.printReplicationInfo() 类似binlong</h2><p><strong>默认会大小为5%的磁盘分区容量， 配置文件oplogSizeMB选项指定大小</strong><br>修改oplog大小: <code>https://docs.mongodb.com/manual/tutorial/change-oplog-size/</code><br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">sanhao:SECONDARY&gt;  rs.printReplicationInfo()</span><br><span class="line">configured oplog size:   1737.5037107467651MB</span><br><span class="line">log length start to end: 2363secs (0.66hrs)</span><br><span class="line">oplog first event time:  Wed Oct 18 2017 15:58:04 GMT+0800 (CST)</span><br><span class="line">oplog last event time:   Wed Oct 18 2017 16:37:27 GMT+0800 (CST)</span><br><span class="line">now:                     Wed Oct 18 2017 16:37:36 GMT+0800 (CST)</span><br></pre></td></tr></table></figure></p>
<h2 id="db-serverStatus-当前实例详细信息"><a href="#db-serverStatus-当前实例详细信息" class="headerlink" title="db.serverStatus() 当前实例详细信息"></a>db.serverStatus() 当前实例详细信息</h2><h2 id="db-serverBuildInfo-mongodb编译环境信息"><a href="#db-serverBuildInfo-mongodb编译环境信息" class="headerlink" title="db.serverBuildInfo() mongodb编译环境信息"></a>db.serverBuildInfo() mongodb编译环境信息</h2><h1 id="mongos路由"><a href="#mongos路由" class="headerlink" title="mongos路由"></a>mongos路由</h1><p>暂略</p>
<h1 id="优化选项"><a href="#优化选项" class="headerlink" title="优化选项"></a>优化选项</h1><p>暂略</p>
<h1 id="要点"><a href="#要点" class="headerlink" title="要点"></a>要点</h1><ul>
<li>先关闭SECONDARY节点,再关闭PRIMARY</li>
<li>当复制集群存活的节点小于大多数时,主节点自动降级为SECONDARY</li>
</ul>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2019-02-22T05:28:07.836Z" itemprop="dateUpdated">2019-02-22 13:28:07</time>
</span><br>


        
        <a href="/2017/10/19/51-mongodb副本集搭建/" target="_blank" rel="external">http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/</a>
        
    </div>
    <footer>
        <a href="http://zhourudong.cn">
            <img src="/img/avatar.png" alt="cucy">
            cucy
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mongodb/">mongodb</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/&title=《mongodb副本集搭建》 — Cucy的博客&pic=http://zhourudong.cn/img/avatar.png" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/&title=《mongodb副本集搭建》 — Cucy的博客&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《mongodb副本集搭建》 — Cucy的博客&url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/&via=http://zhourudong.cn" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2018/01/10/52-ss/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">ss使用</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/09/16/50-mysql之连接and参数and用户权限篇/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">mysql之连接and参数and用户角色权限篇</h4>
      </a>
    </div>
  
</nav>



    














</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>cucy &copy; 2016 - 2021</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/&title=《mongodb副本集搭建》 — Cucy的博客&pic=http://zhourudong.cn/img/avatar.png" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/&title=《mongodb副本集搭建》 — Cucy的博客&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《mongodb副本集搭建》 — Cucy的博客&url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/&via=http://zhourudong.cn" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://zhourudong.cn/2017/10/19/51-mongodb副本集搭建/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="/js/main.min.js?v=1.6.13"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.6.13" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
